<?php

 namespace app\index\service;

 use think\Db;

 /**
  * @author xjy
  */
class ShoponstockService
 {

     //国家仓在途明细列表
     static public function getList($param)
     {
         if(empty($param['down'])){
              $titles=[];
         }else{
              $titles=[
                  'bs_code'=>'业务单号','sku'=>'SKU','price'=>'出库单价（¥）','quantity'=>'在途数量','warehouse_str_out'=>'发货仓库',
                 'warequantity'=>'到货数量','warehouse_str_rec'=>'收货仓库','waredate'=>'收货时间',
                  'differ_num'=>'差异数','differ_money'=>'差异金额（¥）','confirm_status'=>'状态','operator'=>'确认人','operate_time'=>'确认时间'];
         }
        return \app\index\model\ShoponstockModel::getList($param,$titles,"app\index\service\ShoponstockService::convertData");
     }
     public static function convertData($data){
         $warehouse=\app\common\ConfigBase::getWarehouseAll();
         $localno=\app\common\model\ToolModel::select('ship_plan_logistics',[],'local_order_no','','code');
        $confirm=\app\common\model\ToolModel::select('confirm_shoponway',[],'status,operator,operate_time','','concat(code,"_",sku)');
         if($data){
             foreach($data as $key=>&$value){
                $confirmInfo=isset($confirm[$value['code_sku']])? $confirm[$value['code_sku']]:'';
                $value['warehouse_str_out']=isset($warehouse[$value['ship_warehouse_id']]) ? $warehouse[$value['ship_warehouse_id']]:'';
                $value['warehouse_str_rec']=isset($warehouse[$value['receipt_warehouse_id']]) ? $warehouse[$value['receipt_warehouse_id']]:'';
                $value['differ_num']=$value['quantity']-$value['warequantity'];
                $value['differ_money']=$value['differ_num']*$value['price'];
                 $value['status']=!empty($confirmInfo['status']) ?  $confirmInfo['status'] :'1';
                 $value['confirm_status']=!empty($confirmInfo['status']) && $confirmInfo['status']==2 ? '已确认':'待确认';
                 $value['operator']=empty($confirmInfo['operator']) ? '':$confirmInfo['operator'];
                 $value['operate_time']=empty($confirmInfo['operate_time']) ? '':$confirmInfo['operate_time'];
             }
         }
         $data=arraySort($data,'status',SORT_ASC);
         return $data;
     }
 }
